package arrAndstr;

import java.util.HashMap;
import java.util.Map;

/*
    383. 赎金信
 */
public class T383 {

    public boolean canConstruct(String ransomNote, String magazine) {
        Map<Character, Integer> map = new HashMap<>();
        char[] chars = magazine.toCharArray();

        for (char ch : chars) {
            if (!map.containsKey(ch)) {
                map.put(ch, 1);
            } else {
                map.put(ch, map.get(ch)+1);
            }
        }

        chars = ransomNote.toCharArray();
        for (char ch : chars) {
            if (!map.containsKey(ch) || map.get(ch)==0) {
                return false;
            } else {
                map.put(ch, map.get(ch)-1);
            }
        }

        return true;
    }
}
